﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace ZLB_Unility.Extendsions
{
    public static class MethodExtensions
    {
        public static string GetPropertyName<T, K>(this Expression<Func<T, K>> expr) where T : class
        {
            var result = string.Empty;
            if (expr.Body is UnaryExpression)
                result = ((MemberExpression)((UnaryExpression)expr.Body).Operand).Member.Name;
            else if (expr.Body is MemberExpression)
                result = ((MemberExpression)expr.Body).Member.Name;
            else if (expr.Body is ParameterExpression)
                result = ((ParameterExpression)expr.Body).Type.Name;

            return result;
        }

        public static string HandleListStr<T>(this List<T> list)
        {
            string str = string.Format("'{0}'", string.Join(",", list).Replace(",", "','"));
            return str;
        }
    }
}
